package com.atguigu.springcloud.Service.ServiceImpl;

import com.atguigu.springcloud.Dao.PaymentDao;
import com.atguigu.springcloud.Pojo.Payment;
import com.atguigu.springcloud.ResponseBody.Body;
import com.atguigu.springcloud.ResponseBody.Case;
import com.atguigu.springcloud.Service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.StreamingHttpOutputMessage;
import org.springframework.stereotype.Service;

@Service
public class PaymentServiceImpl implements PaymentService {

    @Autowired
    private PaymentDao paymentDao;

    @Value("${server.port}")
    private String serverPort;

    @Override
    public Body addPayment(Payment payment) {
        int i = paymentDao.create(payment);
        if (i<=0){
            Body fail = new Case().fail();
            return fail;
        }else {
            Body success = new Case().success("端口号为："+serverPort);
            return success;
        }
    }

    @Override
    public Body queryPayment(Long id) {
        Payment paymentById = paymentDao.getPaymentById(id);
        if(paymentById != null){
            Body success = new Case().success(paymentById+"端口号为："+serverPort);
            return success;
        }else {
            Body fail = new Case().fail();
            return fail;
        }
    }
}
